/**
 *
 * 2007-11-4 下午03:05:52
 * @author xuhuan
 */

package edu.ccut.saturn.studio.action;

import org.eclipse.gef.palette.CombinedTemplateCreationEntry;
import org.eclipse.gef.palette.ConnectionCreationToolEntry;
import org.eclipse.gef.palette.MarqueeToolEntry;
import org.eclipse.gef.palette.PaletteContainer;
import org.eclipse.gef.palette.PaletteDrawer;
import org.eclipse.gef.palette.PaletteGroup;
import org.eclipse.gef.palette.PaletteRoot;
import org.eclipse.gef.palette.PaletteSeparator;
import org.eclipse.gef.palette.PanningSelectionToolEntry;
import org.eclipse.gef.palette.ToolEntry;
import org.eclipse.gef.requests.CreationFactory;
import org.eclipse.gef.requests.SimpleFactory;
import org.eclipse.jface.resource.ImageDescriptor;

import edu.ccut.saturn.studio.core.util.eclipse.Messages;
import edu.ccut.saturn.studio.logic.ShapesPlugin;
import edu.ccut.saturn.studio.logic.model.Connection;
import edu.ccut.saturn.studio.logic.model.saturn.SaturnActionNode;
import edu.ccut.saturn.studio.logic.model.saturn.SaturnDataNode;
import edu.ccut.saturn.studio.logic.model.saturn.SaturnDecisionNode;
import edu.ccut.saturn.studio.logic.model.saturn.SaturnInformationNode;
import edu.ccut.saturn.studio.logic.model.saturn.SaturnTransformNode;
import edu.ccut.saturn.studio.logic.model.saturn.SaturnViewNode;
import edu.ccut.saturn.studio.logic.model.saturn.SaturnWebContextNode;
import edu.ccut.saturn.studio.logic.model.saturn.action.SaturnDecisionNodeInAction;
import edu.ccut.saturn.studio.logic.model.saturn.action.SaturnInformationNodeInAction;
import edu.ccut.saturn.studio.logic.model.saturn.action.SaturnLogicInAction;
import edu.ccut.saturn.studio.logic.model.saturn.action.SaturnStartNodeInAction;
import edu.ccut.saturn.studio.Activator;

public class ActionEditorPaletteFactory {

	// line setting
	private static final String ACTION_SOLID_LINE = Messages.getString("ActionEditorPaletteFactory.0"); //$NON-NLS-1$
	private static final String ACTION_CREATE_A_SOLID_LINE_CONNECTION = "Create a solid-line connection"; //$NON-NLS-1$
	private static final String ACTION_FALSE_LINE = Messages.getString("ActionEditorPaletteFactory.2"); //$NON-NLS-1$
	private static final String ACTION_CREATE_A_FALSE_CONNECTION = "Create a false connection"; //$NON-NLS-1$

	// tool setting
	private static final String ACTION_DRAWER = Messages.getString("ActionEditorPaletteFactory.4"); //$NON-NLS-1$
	private static final String ACTION_TOOLS = "tools"; //$NON-NLS-1$
	private static final String ACTION_EDITOR_PALETTE_ICONS_CONNECTION_S24_GIF = "/icons/logic/connection_s24.gif"; //$NON-NLS-1$
	private static final String ACTION_EDITOR_PALETTE_ICONS_CONNECTION_S16_GIF = "/icons/logic/connection_s16.gif"; //$NON-NLS-1$

	// basic node setting
	private static final String ACTION_START = Messages.getString("ActionEditorPaletteFactory.29"); //$NON-NLS-1$
	private static final String ACTION_START_NODE = "Start Node"; //$NON-NLS-1$
//	private static final String ACTION_ACTION = "action"; //$NON-NLS-1$
	private static final String ACTION_NAME = Messages.getString("ActionEditorPaletteFactory.37"); //$NON-NLS-1$
	private static final String ACTION_ACTION_NODE = "Start Node"; //$NON-NLS-1$
	private static final String ACTION_LOGIC = Messages.getString("ActionEditorPaletteFactory.logic"); //$NON-NLS-1$
	private static final String ACTION_LOGIC_NODE = "Logic Node"; //$NON-NLS-1$
//	private static final String ACTION_INFORMATION = Messages.getString("ActionEditorPaletteFactory.13"); //$NON-NLS-1$
	private static final String ACTION_INFORMATION =Messages.getString("ActionEditorPaletteFactory.information"); //$NON-NLS-1$
	private static final String ACTION_INFORMATION_NODE = "Information Node"; //$NON-NLS-1$
//	private static final String ACTION_DECISION = Messages.getString("ActionEditorPaletteFactory.15"); //$NON-NLS-1$
	private static final String ACTION_DECISION = Messages.getString("ActionEditorPaletteFactory.decision"); //$NON-NLS-1$
	private static final String ACTION_DECISION_NODE = "Decision Node"; //$NON-NLS-1$
//	private static final String ACTION_TRANSFORM = Messages.getString("ActionEditorPaletteFactory.17"); //$NON-NLS-1$
	private static final String ACTION_TRANSFORM =Messages.getString("ActionEditorPaletteFactory.transform"); //$NON-NLS-1$
	private static final String ACTION_TRANSFORM_NODE = "Transform Node"; //$NON-NLS-1$
//	private static final String ACTION_VIEW = Messages.getString("ActionEditorPaletteFactory.19"); //$NON-NLS-1$
	private static final String ACTION_VIEW = Messages.getString("ActionEditorPaletteFactory.view"); //$NON-NLS-1$
	private static final String ACTION_VIEW_NODE = "View Node"; //$NON-NLS-1$
//	private static final String ACTION_DATA = Messages.getString("ActionEditorPaletteFactory.21"); //$NON-NLS-1$
	private static final String ACTION_DATA = Messages.getString("ActionEditorPaletteFactory.data"); //$NON-NLS-1$
	private static final String ACTION_DATA_NODE = "Data Node"; //$NON-NLS-1$
//	private static final String ACTION_WEB_CONTEXT = Messages.getString("ActionEditorPaletteFactory.23"); //$NON-NLS-1$
	private static final String ACTION_WEB_CONTEXT =Messages.getString("ActionEditorPaletteFactory.web"); //$NON-NLS-1$
	private static final String ACTION_WEB_CONTEXT_NODE = "webContext Node"; //$NON-NLS-1$

	private static PaletteContainer createShapesDrawer() {

		PaletteDrawer componentsDrawer = new PaletteDrawer(ACTION_DRAWER);

		CombinedTemplateCreationEntry startEntry = new CombinedTemplateCreationEntry(
				ACTION_START, ACTION_START_NODE, SaturnStartNodeInAction.class,
				new SimpleFactory(SaturnStartNodeInAction.class),
				ImageDescriptor.createFromFile(ShapesPlugin.class,
//						IconNames.START_MINI_NAME), ImageDescriptor
						Activator.START_MINI_NAME), ImageDescriptor
						.createFromFile(ShapesPlugin.class,
//								IconNames.START_NAME));
								Activator.START_NAME));
		CombinedTemplateCreationEntry actionEntry = new CombinedTemplateCreationEntry(
				ACTION_NAME, ACTION_ACTION_NODE, SaturnActionNode.class,
				new SimpleFactory(SaturnActionNode.class), ImageDescriptor
						.createFromFile(ShapesPlugin.class,
//								IconNames.SATURN_ACTION_MIN), ImageDescriptor
								Activator.SATURN_ACTION_MIN), ImageDescriptor
						.createFromFile(ShapesPlugin.class,
//								IconNames.SATURN_ACTION_MAX));
								Activator.SATURN_ACTION_MAX));

		CombinedTemplateCreationEntry logicEntry = new CombinedTemplateCreationEntry(
				ACTION_LOGIC, ACTION_LOGIC_NODE, SaturnLogicInAction.class,
				new SimpleFactory(SaturnLogicInAction.class), ImageDescriptor
						.createFromFile(ShapesPlugin.class,
//								IconNames.LOGIC_MINI_NAME), ImageDescriptor
								Activator.LOGIC_MINI_NAME), ImageDescriptor
						.createFromFile(ShapesPlugin.class,
//								IconNames.LOGIC_MANX_NAME));
								Activator.LOGIC_MANX_NAME));
		CombinedTemplateCreationEntry informationEntry = new CombinedTemplateCreationEntry(
				ACTION_INFORMATION, ACTION_INFORMATION_NODE,
				SaturnInformationNode.class, new SimpleFactory(
						SaturnInformationNodeInAction.class), ImageDescriptor
						.createFromFile(ShapesPlugin.class,
//								IconNames.INFORMATION_MINI_NAME),
								Activator.INFORMATION_MINI_NAME),
				ImageDescriptor.createFromFile(ShapesPlugin.class,
//						IconNames.INFORMATION_NAME));
						Activator.INFORMATION_NAME));

		CombinedTemplateCreationEntry deciseionEntry = new CombinedTemplateCreationEntry(
				ACTION_DECISION, ACTION_DECISION_NODE, SaturnDecisionNode.class,
				new SimpleFactory(SaturnDecisionNodeInAction.class),
				ImageDescriptor.createFromFile(ShapesPlugin.class,
//						IconNames.DECISION_MINI_NAME), ImageDescriptor
						Activator.DECISION_MINI_NAME), ImageDescriptor
						.createFromFile(ShapesPlugin.class,
//								IconNames.DECISION_MANX_NAME));
								Activator.DECISION_MANX_NAME));

		CombinedTemplateCreationEntry transformEntry = new CombinedTemplateCreationEntry(
				ACTION_TRANSFORM, ACTION_TRANSFORM_NODE,
				SaturnTransformNode.class, new SimpleFactory(
						SaturnTransformNode.class), ImageDescriptor
						.createFromFile(ShapesPlugin.class,
//								IconNames.SATURN_TTANSFORM_MIN), ImageDescriptor
								Activator.SATURN_TTANSFORM_MIN), ImageDescriptor
						.createFromFile(ShapesPlugin.class,
//								IconNames.SATURN_TTANSFORM_MAX));
								Activator.SATURN_TTANSFORM_MAX));

		CombinedTemplateCreationEntry viewEntry = new CombinedTemplateCreationEntry(
				ACTION_VIEW, ACTION_VIEW_NODE, SaturnViewNode.class,
				new SimpleFactory(SaturnViewNode.class), ImageDescriptor
						.createFromFile(ShapesPlugin.class,
								Activator.VIEW_MIN_NAME), ImageDescriptor
//								IconNames.VIEW_MIN_NAME), ImageDescriptor
						.createFromFile(ShapesPlugin.class,
								Activator.VIEW_MAX_NAME));
//								IconNames.VIEW_MAX_NAME));

		CombinedTemplateCreationEntry dataEntry = new CombinedTemplateCreationEntry(
				ACTION_DATA, ACTION_DATA_NODE, SaturnDataNode.class,
				new SimpleFactory(SaturnDataNode.class), ImageDescriptor
						.createFromFile(ShapesPlugin.class,
//								IconNames.DATA_MIN_NAME), ImageDescriptor
								Activator.DATA_MIN_NAME), ImageDescriptor
						.createFromFile(ShapesPlugin.class,
//								IconNames.DATA_MAX_NAME));
								Activator.DATA_MAX_NAME));

		CombinedTemplateCreationEntry webContextEntry = new CombinedTemplateCreationEntry(
				ACTION_WEB_CONTEXT, ACTION_WEB_CONTEXT_NODE,
				SaturnWebContextNode.class, new SimpleFactory(
						SaturnWebContextNode.class), ImageDescriptor
						.createFromFile(ShapesPlugin.class,
//								IconNames.SATURN_WEBCONTEXT_SMALL),
								Activator.SATURN_WEBCONTEXT_SMALL),
				ImageDescriptor.createFromFile(ShapesPlugin.class,
//						IconNames.SATURN_WEBCONTEXT_BIG));
						Activator.SATURN_WEBCONTEXT_BIG));

		componentsDrawer.add(startEntry);
		componentsDrawer.add(actionEntry);
		componentsDrawer.add(logicEntry);
		componentsDrawer.add(informationEntry);
		componentsDrawer.add(deciseionEntry);
		componentsDrawer.add(transformEntry);
		componentsDrawer.add(viewEntry);
		componentsDrawer.add(dataEntry);
		componentsDrawer.add(webContextEntry);

		return componentsDrawer;
	}

	static PaletteRoot createPalette() {
		PaletteRoot palette = new PaletteRoot();
		palette.add(createToolsGroup(palette));
		palette.add(createShapesDrawer());
		return palette;
	}

	private static PaletteContainer createToolsGroup(PaletteRoot palette) {
		PaletteGroup toolGroup = new PaletteGroup(ACTION_TOOLS);

		ToolEntry tool = new PanningSelectionToolEntry();
		toolGroup.add(tool);
		palette.setDefaultEntry(tool);

		toolGroup.add(new MarqueeToolEntry());

		toolGroup.add(new PaletteSeparator());

		tool = new ConnectionCreationToolEntry(ACTION_SOLID_LINE,
				ACTION_CREATE_A_SOLID_LINE_CONNECTION, new CreationFactory() {
					public Object getNewObject() {
						return null;
					}

					public Object getObjectType() {
						return Connection.SOLID_CONNECTION;
					}
				}, ImageDescriptor.createFromFile(ShapesPlugin.class,
						ACTION_EDITOR_PALETTE_ICONS_CONNECTION_S16_GIF),
				ImageDescriptor.createFromFile(ShapesPlugin.class,
						ACTION_EDITOR_PALETTE_ICONS_CONNECTION_S24_GIF));
		toolGroup.add(tool);
		tool = new ConnectionCreationToolEntry(ACTION_FALSE_LINE,
				ACTION_CREATE_A_FALSE_CONNECTION, new CreationFactory() {
					public Object getNewObject() {
						return null;
					}

					public Object getObjectType() {
						return Connection.DASHED_CONNECTION;
					}
				}, ImageDescriptor.createFromFile(ShapesPlugin.class,
//						IconNames.DASHED_CONNECTION_MIN), ImageDescriptor
						Activator.DASHED_CONNECTION_MIN), ImageDescriptor
						.createFromFile(ShapesPlugin.class,
								Activator.DASHED_CONNECTION_MAX));
//								IconNames.DASHED_CONNECTION_MAX));
		toolGroup.add(tool);
		return toolGroup;
	}

	/** Utility class. */
	private ActionEditorPaletteFactory() {
		// Utility class
	}
}
